home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
007a
/
899track.zip
/
899EDIT.PRO
< prev
next >
Wrap
Text File
|
1990-03-06
|
19KB
|
424 lines
project "899"
include "899glob.pro"
/* This file is interface to the main edit window (#100) and is
an attempt to standardize the editing procedure of descriptions */
% GLOBAL PREDICATES IN THIS FILE::
% edit_setup
% edit_descr
% edit_retrieve
% edit_setdown
% IMPORTANT -- REQUIRES that window #100 already has been created somewhere
% else by the main caller.
DATABASE - edit_def
determ window_contents(gsList) % Hold all the strings in the window
window_line(INTEGER,gs) % X Locatation(String Number) [Y assumed 0] and the string located there
determ window_def(INTEGER,INTEGER,INTEGER,INTEGER) % Window Max Diplayable Row and Max Diplayable Column and Attribute/Inverse
determ curr_str(INTEGER) % Current working string number)
PREDICATES
enumerate(gsList,INTEGER) % Numbers the list of strings starting at INT to whatever
renum(INTEGER,INTEGER) % renumbers the window_lines given Starting Number and Addition Adjustment (+-1)
redef(INTEGER,INTEGER) % used bu renum for partial sorting of window_lines
reint_normal(INTEGER,INTEGER,INTEGER)
reint_reverse(INTEGER,INTEGER,INTEGER)
rebuild_contents % after some king of funtion this rebuilds
display_str(INTEGER,INTEGER) % display from First X position starting with String Y
d_str(INTEGER,INTEGER,INTEGER)
key_dispatch(key,INTEGER,INTEGER,INTEGER)
scr_dispatch(key,INTEGER,INTEGER,INTEGER)
cursor_check(INTEGER,INTEGER) % Check's the cursor
insert_line(INTEGER)
delete_line(INTEGER)
get_c_spec(INTEGER,gs,INTEGER) % Returns specs of the current thing
rem_c_spec(INTEGER,gs,INTEGER) % Returns data of current and removes it
get_max_def(INTEGER) % Returns the number of the max
line_sort
CLAUSES
edit_descr :- % The call to this assumes that edit_setup has already been called
makewindow(OldWindow,_,_,_,_,_,_,_), % Save old window
shiftwindow(100), % Just make sure we are in this window
getbacktrack(Btop), % get this for we are doing much nondeterminism from here on
repeat,
getkey(Press,[cr, esc, del, bdel, end, home, up, down, left, right,
pgup, pgdn, ctrl_bdel, num(0), num(1), num(2), num(3), num(4), num(5),
num(6), num(7), num(8), num(9), char('A'), char('B'), char('C'),
char('D'), char('E'), char('F'), char('G'), char('H'), char('I'),
char('J'), char('K'), char('L'), char('M'), char('N'), char('O'),
char('P'), char('Q'), char('R'), char('S'), char('T'), char('U'),
char('V'), char('W'), char('X'), char('Y'), char('Z'), char('a'),
char('b'), char('c'), char('d'), char('e'), char('f'), char('g'),
char('h'), char('i'), char('j'), char('k'), char('l'), char('m'),
char('n'), char('o'), char('p'), char('q'), char('r'), char('s'),
char('t'), char('u'), char('v'), char('w'), char('x'), char('y'),
char('z'), char('!'), char('@'), char('#'), char('$'), char('%'),
char('^'), char('&'), char('*'), char('('), char(')'), char('-'),
char('_'), char('='), char('+'), char('\\'),char('|'), char('['),
char('{'), char(']'), char('}'), char(';'), char(':'), char(','),
char('<'), char('.'), char('>'), char('/'), char('?'), char('`'),
char('~'), char('"'), char('''), char(' ')]), % get a keypress
curr_str(StrNumber), % get the string number we are on top of
cursor(CurrX,CurrY), % get our current cursor locations
getbacktrack(Ktop),
key_dispatch(Press,CurrX,CurrY,StrNumber),
cutbacktrack(Ktop),
getbacktrack(Stop),
scr_dispatch(Press,CurrX,CurrY,StrNumber),
cutbacktrack(Stop),
Press = esc,
line_sort,
rebuild_contents,
cutbacktrack(Btop),
shiftwindow(OldWindow).
display_str(StartX,StringNumber) :-
cursor(OldX,OldY), % Get the old
cursor(StartX,0), % set new
window_def(MaxX,_,_,_),
getbacktrack(Btop),
d_str(StartX,MaxX,StringNumber),
cutbacktrack(Btop),
cursor(OldX,OldY).
d_str(MaxX,MaxX,StrNum) :- % A terminate when we reached maximum row number
window_line(StrNum,StringToPrint), !,
writef("%-77",StringToPrint).
d_str(CurrX,MaxX,StNum) :-
window_line(StNum,StringToPrint), !, % This may fail if to far past
writef("%-77",StringToPrint), NextX = CurrX + 1, NextStr = StNum + 1,
cursor(NextX,0),
d_str(NextX,MaxX,NextStr).
d_str(_,_,_).
edit_setup(ListOfStrings,Title) :-
assert(window_contents(ListOfStrings),edit_def), % Add this to our current definition
assert(curr_str(0),edit_def),
makewindow(CurrW,_,_,_,_,_,_,_), % Get the current Window to save
shiftwindow(100), % Move to our window
change_window_title(Title),
makewindow(_,Attribute,_,_,_,_,Wrsize,Wcsize), % Get OUR window's thing
cursor(0,0),
UsableRows = Wrsize - 3, % Calculate usable rows
UsableColumns = Wcsize - 3, % calculate usable columns
inverse(Attribute,InvAttribute), % calcluate the inverse attribute
assert(window_def(UsableRows,UsableColumns,Attribute,InvAttribute),edit_def),
enumerate(ListOfStrings,0), % and enumerate the given list of strings
getbacktrack(Btop),
display_str(0,0),
cutbacktrack(Btop),
cursor(0,0),
shiftwindow(CurrW).
enumerate([],LastNumber) :- !, % Terminating condition
assert(window_line(LastNumber,terminate),edit_def).
enumerate([Astring|RestOfList],StringNumber) :-
assert(window_line(StringNumber,Astring),edit_def), % Place a string in memory
NextNumber = StringNumber+1,
enumerate(RestOfList,NextNumber).
edit_retrieve(ListOfStrings) :- % Return our list of strings -- non destrictive
window_contents(ListOfStrings).
edit_setdown(ListOfStrings) :-
retract(window_contents(ListOfStrings),edit_def),
retractall(_,edit_def),
makewindow(CurrW,_,_,_,_,_,_,_), % Get the current Window to save
shiftwindow(100), % Move to our window
clearwindow,
change_window_title(edit_title),
shiftwindow(CurrW).
rebuild_contents :-
retract(window_contents(_),edit_def),
findall(Data,window_line(_,Data),NewList),
expgsList(terminate,NewList,ExtraNewList), % Take the terminator out
assert(window_contents(ExtraNewList),edit_def).
renum(StartingNumber,AdjustmentFactor) :- % POSITIVE ADJUSTMENT nonzero
AdjustmentFactor > 0, % This clause is for positive adjustment thuss adding a line
StartingNumber <> 0, !,
window_line(LastNumber,terminate), % Grab the last line number which will terminate this thing
BreakingPoint = StartingNumber - 1, % for renumbering
redef(0,BreakingPoint), % redefine for sorting the numbers
reint_reverse(StartingNumber,LastNumber,AdjustmentFactor),
asserta(window_line(StartingNumber,""),edit_def),
NewLastNumber = LastNumber + AdjustmentFactor,
redef(StartingNumber,NewLastNumber). % and thus the information is sorted
renum(StartingNumber,AdjustmentFactor) :- % POSITIVE ADJUSTMENT ZERO!!
AdjustmentFactor > 0, !, % This clause is for positive adjustment thuss adding a line
window_line(LastNumber,terminate), % Grab the last line number which will terminate this thing
reint_reverse(StartingNumber,LastNumber,AdjustmentFactor),
asserta(window_line(StartingNumber,""),edit_def),
NewLastNumber = LastNumber + AdjustmentFactor,
redef(StartingNumber,NewLastNumber). % and thus the information is sorted
renum(StartingNumber,AdjustmentFactor) :- % NEGATIVE ADJUSTMENT
window_line(LastNumber,terminate),
retract(window_line(StartingNumber,_),edit_def), % Take it out
NewS = StartingNumber + 1,
reint_normal(NewS,LastNumber,AdjustmentFactor), % adjust all above
NewLastNumber = LastNumber + AdjustMentfactor,
redef(0,NewLastNumber). % Sort it.
reint_reverse(StartingNumber,StartingNumber,Adj) :- !, % Stopping
retract(window_line(StartingNumber,Data),edit_def),
NewNum = StartingNumber + Adj,
asserta(window_line(NewNum,Data),edit_def).
reint_reverse(EndingNumber,CurrNum,Adj) :-
retract(window_line(CurrNum,Data),edit_def),
NewNum = CurrNum + Adj,
asserta(window_line(NewNum,Data),edit_def),
NextElement = CurrNum - Adj,
reint_reverse(EndingNumber,NextElement,Adj).
reint_normal(LastNumber,LastNumber,Adj) :- !,
retract(window_line(LastNumber,Data),edit_def),
NewNum = LastNumber + Adj,
asserta(window_line(NewNum,Data),edit_def).
reint_normal(CurrNum,LastNum,Adj) :-
retract(window_line(CurrNum,Data),edit_def),
NewNum = CurrNum + Adj,
asserta(window_line(NewNum,Data),edit_def),
NextElement = CurrNum - Adj,
reint_normal(NextElement,LastNum,Adj).
redef(BreakingPoint,BreakingPoint) :- !, % Last one to put back
retract(window_line(BreakingPoint,Data),edit_def),
assertz(window_line(BreakingPoint,Data),edit_def).
redef(CurrLine,BreakingPoint) :-
retract(window_line(CurrLine,Data),edit_def),
assertz(window_line(CurrLine,Data),edit_def),
NextLine = CurrLine + 1,
redef(NextLine,BreakingPoint).
key_dispatch(esc,_,_,_) :- !. % The terminating condition
key_dispatch(cr,_,CurrY,Cstr) :-
get_max_def(MaxDef),
Cstr < MaxDef, !,
insert_line(Cstr), /* Do this */
NextLine = Cstr + 1,
rem_c_spec(NextLine,Data,_), % Remove current information
frontstr(CurrY,Data,StuffToLeave,StuffToGo), % Split the string
rem_c_spec(Cstr,_,_),
assert(window_line(Cstr,StuffToLeave),edit_def),
assert(window_line(NextLine,StuffToGo),edit_def),
line_sort. % Sort
key_dispatch(ctrl_bdel,_,_,CstrNum) :-
get_max_def(MaxStrN),
CstrNum < MaxStrN, !,
delete_line(CstrNum).
key_dispatch(char(C),_,0,StrNum) :- % This is for the beginning of the string
get_max_def(MaxDef),
StrNum < MaxDef, % So we don't edit the terminator
get_c_spec(StrNum,_,DataLen),
window_def(_,MaxY,_,_),
DataLen < (MaxY-1), !, % So we cant go past the end
rem_c_spec(StrNum,Data,_),
str_char(Stc,C),
concat(Stc,Data,NewString), % Append the char to the front
assert(window_line(StrNum,NewString),edit_def),
line_sort. % Resort the items
key_dispatch(char(C),_,CurrY,StrNum) :- % Here may be in middle or at end
get_max_def(MaxN),
StrNum < MaxN, % So we don't edit terminator
get_c_spec(StrNum,Xdata,ItsLength),
window_def(_,MaxY,_,_),
ItsLength < (MaxY-1), % So we don't go past the end
CurrY >= ItsLength, !, % From here on out, the cursor is at the end of the line
rem_c_spec(StrNum,_,_), % Take it out
str_char(CharToS,C), % Convert Char to string
concat(Xdata,ChartoS,NewData), % Make the new string
assert(window_line(StrNum,NewData),edit_def),
line_sort. % Resort
key_dispatch(char(C),_,CurrY,StrNum) :- !, /* Here, the cursor is in the middle of the string */
get_max_def(MaxDef),
StrNum < MaxDef, % So we don't edit terminator
get_c_spec(StrNum,_,DataLen),
window_def(_,MaxY,_,_), % so we dont' go past end
DataLen < (MaxY-1), !,
rem_c_spec(StrNum,Xdata,_), % take it out
frontstr(CurrY,Xdata,LeftOfCursor,RightOfCursor),
str_char(Cs,C), % convert to char
concat(LeftOfCursor,Cs,NewLeftOfCursor),
concat(NewLeftOfCursor,RightOfCursor,NewString),
assert(window_line(StrNum,NewString),edit_def),
line_sort. % sort
key_dispatch(bdel,_,CurrY,StrNum) :- % Backspace Key hit
CurrY > 0,
get_max_def(MaxDef),
StrNum < MaxDef, !,
rem_c_spec(StrNum,Data,_), % Take the string
PosToDel = CurrY - 1, % The char to delete is here!
frontstr(PosToDel,Data,LeftHalf,RightHalf),
frontchar(RightHalf,_,NewRightHalf), % Delete the front on second
concat(LeftHalf,NewRightHalf,NewData),
assert(window_line(StrNum,NewData),edit_def),
line_sort. % Resort
key_dispatch(del,_,CurrY,StrNum) :- % DEl Key
get_max_def(MaxDef),
StrNum < MaxDef,
get_c_spec(StrNum,Data,DataLen),
CurrY < DataLen, !, % conditionary clause
rem_c_spec(StrNum,_,_),
frontstr(CurrY,Data,LeftHalf,RightHalf),
frontchar(RightHalf,_,NewRightHalf), % Delete the front on second
concat(LeftHalf,NewRightHalf,NewData),
assert(window_line(StrNum,NewData),edit_def),
line_sort. % Resort
key_dispatch(num(N),CurrX,CurrY,StrNum) :- !,
Cn = N + $30,
char_int(Car,Cn),
key_dispatch(char(Car),CurrX,CurrY,StrNum).
key_dispatch(up,_,_,CurrStringNumber) :-
NewStNum = CurrStringNumber - 1,
window_line(NewStNum,_), !, % If a definition exists
retract(curr_str(CurrStringNumber),edit_def),
assert(curr_str(NewStNum),edit_def).
key_dispatch(down,_,_,CstrNum) :-
NewStNum = CstrNum + 1,
window_line(NewStNum,_), !, % If the next line exists
retract(curr_str(CstrNum),edit_def),
assert(curr_str(NewStNum),edit_def).
key_dispatch(_,_,_,_).
scr_dispatch(esc,_,_,_) :- !. % The termiateing condition
scr_dispatch(cr,CurrX,_,Cstr) :-
FirstElem = Cstr - CurrX,
display_str(0,FirstElem), % Redisplay
window_def(MaxX,_,_,_),
CurrX = MaxX, !,
NewD = Cstr + 1,
StartStr = NewD - MaxX,
display_str(0,StartStr),
cursor_check(MaxX,0).
scr_dispatch(cr,CurrX,_,Cstr) :-
!, NewX = CurrX + 1,
cursor(NewX,0),
retract(curr_str(_),edit_def),
NewStr = Cstr + 1,
assert(curr_str(NewStr),edit_def).
scr_dispatch(ctrl_bdel,CurrX,_,CtrnNum) :- !,
FirstElem = CtrnNum - CurrX,
clearwindow,
display_str(0,FirstElem),
cursor(CurrX,0).
scr_dispatch(char(_),CurrX,CurrY,StrNum) :- % the same for all chars
get_max_def(MaxDef),
StrNum < MaxDef,
get_c_spec(StrNum,Data,DataLen), % Grab the new line
window_def(_,MaxY,_,_),
DataLen < MaxY, !,
cursor(CurrX,0), writef("%-77",Data),
NewY = CurrY + 1,
cursor(CurrX,NewY).
scr_dispatch(bdel,CurrX,CurrY,StrNum) :-
CurrY > 0,
get_max_def(MaxDef),
StrNum < MaxDef, !,
get_c_spec(StrNum,Data,_),
cursor(CurrX,0), writef("%-77",Data),
NewY = CurrY - 1,
cursor(CurrX,NewY).
scr_dispatch(del,CurrX,CurrY,StrNum) :-
get_max_def(MaxDef),
StrNum < MaxDef, !,
get_c_spec(StrNum,Data,_),
cursor(CurrX,0), writef("%-77",Data),
cursor(CurrX,CurrY).
scr_dispatch(num(N),CurrX,CurrY,StrNum) :- !,
Cn = N + $30,
char_int(Car,Cn),
scr_dispatch(char(Car),CurrX,CurrY,StrNum).
scr_dispatch(home,CurrX,_,_) :-
!, cursor(CurrX,0).
scr_dispatch(end,CurrX,_,StrNum) :-
!, get_c_spec(StrNum,_,NewY), cursor(CurrX,NewY).
scr_dispatch(up,0,CurrY,StrNum) :-
curr_str(ActualC), % Grab the actual current string number
ActualC <> StrNum, !, % If they are the same, then key_dispatch clause failed
% At this point the entire window must be refreshed!!
scroll(-1,0), % scrol the screen
window_line(ActualC,Stp),
cursor(0,0),
writef("%-77",Stp),
cursor_check(0,CurrY).
scr_dispatch(up,CurrX,CurrY,StrNum) :- % here, there are 2 ways the above may have failed
curr_str(ActualC), % Grab the actual current string number
ActualC <> StrNum, !, % If they are the same, then key_dispatch clause failed and above failed
NewX = CurrX - 1, % Thus simply move the cursor up one
cursor_check(NewX,CurrY).
scr_dispatch(down,CurrX,CurrY,StrNum) :-
curr_str(ActualC),
ActualC <> StrNum, % Meaning that there is another displayable string
window_def(MaxRow,_,_,_),
CurrX = MaxRow, !, % Means that the window must be refreshed
scroll(1,0),
window_line(ActualC,Stp),
cursor(MaxRow,0),
writef("%-77",Stp),
cursor_check(CurrX,CurrY).
scr_dispatch(down,CurrX,CurrY,StrNum) :-
curr_str(ActualC),
ActualC <> StrNum,!, % Meaning that there is another displayable string
NextRow = CurrX + 1,
cursor_check(NextRow,CurrY).
scr_dispatch(left,CurrX,CurrY,_) :-
NewY = CurrY - 1,
NewY >= 0, !,
cursor(CurrX,NewY).
scr_dispatch(right,CurrX,CurrY,StrNum) :-
window_line(StrNum,Str),
str_len(Str,MaxY),
NewY = CurrY + 1,
NewY <= MaxY, !,
cursor(CurrX,NewY).
scr_dispatch(_,_,_,_).
cursor_check(CurrX,CurrY) :-
curr_str(CurrNum), window_line(CurrNum,Str), str_len(Str,MaxY),
CurrY > MaxY, !, % If the newy is bigger than line max, then adjust
cursor(CurrX,MaxY).
cursor_check(X,Y) :-
cursor(X,Y). % Otherwise, it's fine
insert_line(CurrentStringNumber) :-
/* This inserts an empty string before the current string so that
upon exit, the CurrentStringNumber is the number of "" and
the old String number is one greater */
renum(CurrentStringNumber,1). /* Readgust all the numbers by one */
delete_line(CurrentStringNumber) :-
/* This delete the current string number line so that upon exit,
the base will have one less string */
renum(CurrentStringNumber,-1). /* Readjust internally */
get_c_spec(StrNum,Data,DataLen) :-
getbacktrack(Btop),
window_line(StrNum,Data),
str_len(Data,DataLen),
cutbacktrack(Btop).
rem_c_spec(StrNum,Data,DataLen) :-
getbacktrack(Btop),
get_c_spec(StrNum,Data,DataLen),
retract(window_line(StrNum,_),edit_def),
cutbacktrack(Btop).
get_max_def(MaxNum) :-
getbacktrack(Btop),
window_line(MaxNum,terminate),
cutbacktrack(Btop).
line_sort :-
window_line(MaxDef,terminate), % Grab the terminate
redef(0,MaxDef).